// PermissionDirective.js
import { useSysConfigStore } from '@/stores/sysConfig'

export const permissionDirective = {
    mounted(el, binding) {
        // 获取权限标识  
        const permission = binding.value;
        // 假设有一个权限检查函数  
        const hasPermission = checkPermission(permission);
        // 根据权限控制按钮的显示或禁用  
        if (!hasPermission) {
            el.style.display = 'none'; // 或者 el.disabled = true;  
        }
    }
};

export const roleDirective = {
    mounted(el, binding) {
        // 获取权限标识  
        const role = binding.value;
        // 假设有一个权限检查函数  
        const hasRole = checkRole(role);
        // 根据权限控制按钮的显示或禁用  
        if (!hasRole) {
            el.style.display = 'none'; // 或者 el.disabled = true;  
        }
    }
};
// 权限检查函数  
function checkPermission(permission) {
    const sysConfig = useSysConfigStore()
    if(sysConfig.permissionList){
        return sysConfig.permissionList.includes(permission)
    }
    return false
}

// 角色检查函数  
function checkRole(role) {
    const sysConfig = useSysConfigStore()
    if(sysConfig.roleList){
        return sysConfig.roleList.includes(role)
    }
    return false
}
